package com.junchenrobot.mes.controller;


import com.junchenrobot.mes.domain.Device;
import com.junchenrobot.mes.response.BaseResponse;
import com.junchenrobot.mes.service.ManualTaskService;
import com.junchenrobot.mes.service.TaskService;
import com.junchenrobot.mes.vo.*;
import com.junchenrobot.mes.vo.param.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/mes/task", produces = "application/json;charset=utf-8")
public class TaskController {

    private final ManualTaskService manualTaskService;

    private final TaskService taskService;

    @Autowired
    public TaskController(ManualTaskService manualTaskService,
                          TaskService taskService) {
        this.manualTaskService = manualTaskService;
        this.taskService = taskService;
    }

    /**
     * 手动添加任务
     *
     * @param manualTaskParam 人工任务参数
     * @return {@link BaseResponse}
     */
    @PostMapping("/manual/addTask")
    public BaseResponse manualAddTask(@RequestBody ManualTaskParam manualTaskParam) {
        //  手动添加任务
        return manualTaskService.manualAddTask(manualTaskParam);
    }

    /**
     * 前段分派任务(轮循)
     *
     * @return
     */
    @GetMapping("/manual/dispatch")
    public BaseResponse manualDispatch() {
        return manualTaskService.dispatchTask();
    }


    /**
     * 取消任务
     * 手动取消任务
     *
     * @param taskIdParam 任务id参数
     * @return {@link BaseResponse}
     */
    @DeleteMapping("/manual/delete")
    public BaseResponse cancelTask(@RequestBody TaskIdParam taskIdParam) {
        //  手动删除任务
        return manualTaskService.cancelTask(taskIdParam);
    }

    /**
     * 列出所有未完成的任务
     *
     * @param page 页面
     * @param num  全国矿工工会
     * @return {@link PageRecordVo}<{@link TaskInfoVo}>
     */
    @GetMapping("/info/list")
    public PageRecordVo<TaskInfoVo> listTask(@RequestParam("page") Integer page,
                                             @RequestParam("num") Integer num) {
        return taskService.listTask(new PageParam(page, num));
    }

    /**
     * 任务列表
     *
     * @param page 页面
     * @param num  全国矿工工会
     * @return {@link PageRecordVo}<{@link TaskHistoryVo}>
     */
    @GetMapping("/info/historylist")
    public PageVo historyList(@RequestParam("page") Integer page,
                                                   @RequestParam("num") Integer num) {
        return taskService.historyList(new PageParam(page, num));
    }


    /**
     * 接丝任务
     *
     * @return
     */
    @GetMapping("/info/waiting/list")
    public List<WaitingTaskVo> listWaitingTask() {
        return taskService.listWaitingTask();
    }

    /**
     * 卷绕机络筒后停留时间列表
     *
     * @return
     */
    @GetMapping("/info/windertime/list")
    public List<WinderTimeVo> listWinderTime() {
        return taskService.listWinderTime();
    }

    /**
     * 模糊查询卷绕机络筒后停留时间列表
     *
     * @return
     */
    @GetMapping("/info/blurwindertime/list")
    public List<WinderTimeVo> listWinderTime(@RequestParam("winderName") String winderName) {
        return taskService.blurListWinderTime(winderName);
    }

    /**
     * 修改停留时间
     */
    @PostMapping("/info/windertime/update")
    public BaseResponse updateWinderTime(@RequestBody WinderTimeParam winderTimeParam){
        return manualTaskService.updateWinderTime(winderTimeParam);
    }

    /**
     * 所有avg小车状态
     */
    @GetMapping("/info/device/list")
    public List<DeviceVo> deviceList() {
        return taskService.deviceVoList();
    }
    /**
     * 禁用avg小车状态
     */
    @PostMapping("/manual/update/disable")
    public BaseResponse updateDisableDevice(@RequestBody DeviceParam deviceParam){
        return manualTaskService.updateDisableDevice(deviceParam);
    }
    /**
     * 启用avg小车状态
     */
    @PostMapping("/manual/update/enable")
    public BaseResponse updateEnableDevice(@RequestBody DeviceParam deviceParam){
        return manualTaskService.updateEnableDevice(deviceParam);
    }

}
